package com.emotion.recognition.server.som;

import java.util.Map;
import java.util.Random;

import com.google.common.collect.Maps;


public class FeatureNode {

	private final int positionX, positionY;
	private final double[] weights;
	private final Map<String, Integer> values = Maps.newHashMap();

	public FeatureNode(int x, int y, int inputSize) {
		this.positionX = x;
		this.positionY = y;

		// Initialize nodes to random weights.
		weights = new double[inputSize];
		Random generator = new Random();
		for (int i = 0; i < inputSize; ++i) {
			weights[i] = generator.nextDouble();
		}
	}

	public double[] getWeights() {
		return this.weights;
	}

	public int getPositionX() {
		return positionX;
	}

	public int getPositionY() {
		return positionY;
	}

	public Map<String, Integer> getValues() {
		return values;
	}

	public void setValue(String value) {
		// Used for debugging purposes. What inputs choose this node as BMU?
        String key = value;// .substring(0, 2);
		int count = values.containsKey(key) ? values.get(key) + 1 : 1;
        values.put(value/* .substring(0, 2) */, count);
	}

	public void setWeight(double newWeight, int k) {
		this.weights[k] = newWeight;		
	}
}
